package CarRental;

//汽车租赁公司
public class CarRental {
    private String name, address, telephone;//公司名称，地址，电话，,customer租车人
    private double charterMoney = 0;//租车总输入
    private Automobile[] a = new Automobile[100];
    private int count = 0;
    private int tally = 0;//记录已租车辆个数
    private Tenant[] t = new Tenant[1000];
    private int count1 = 0;//记录租车信息记录

    public CarRental() {

    }

    public CarRental(String name, String address, String telephone) {
        this.name = name;
        this.address = address;
        this.telephone = telephone;
    }

    //显示公司信息
    public void show() {
        System.out.println("公司名称：" + this.name + "\n公司地址：" + this.address +
                "\n公司电话：" + this.telephone);
    }

    //车辆信息
    public void showCar() {
        System.out.println("车型" + "   车牌" + "   品牌" + "   座位" + "   日租金" + "   当前状态");
        for (int i = 0; i < count; i++) {
            a[i].showCar();
        }
    }

    //加新车
    public boolean add(Automobile newA) {
        if (count >= a.length) {
            Automobile[] ax = new Automobile[a.length + 100];
            for (int i = 0; i < count; i++) {
                ax[i] = a[i];
            }
            a = ax;
        }
        for (int i = 0; i < count; i++) {
            if (newA.getLicensePlate().equals(a[i].getLicensePlate())) {
                System.out.println("车牌已存在");
                return false;
            }
        }
        a[count++] = newA;
        return true;
    }


    //租车显示
    public void rentshow(int ch) {
        for (int i = 0; i < count; i++) {
            if (a[i].isState()) {
                if (ch == 1 && a[i] instanceof Car) {
                    a[i].showCar();
                } else if (ch == 2 && a[i] instanceof Coach) {
                    a[i].showCar();
                }
            }
        }
    }

    //租车
    public Automobile rent(String licensePlate) {
        for (int i = 0; i < count; i++) {
            if (licensePlate.equals(a[i].getLicensePlate())) {
                if (!a[i].isState()) {
                    System.out.println("车辆已租出，请选则其他可租车辆。");
                    return null;
                }
                a[i].setState(false);
                tally++;
                return a[i];
            }
        }
        return null;
    }

    //还车
    public boolean returnCar(String licensePlate) {
        for (int i = 0; i < count; i++) {
            if (licensePlate.equals(a[i].getLicensePlate())) {
                if (!a[i].isState()) {
                    a[i].setState(true);
                    tally--;
                    return true;
                }
                if (a[i].isState()) {
                    return false;
                }
            }
        }
        return false;
    }

    //报废  有问题！！！！
    public boolean scrapCar(String licensePlate) {
        for (int i = 0; i < count; i++) {
            if (licensePlate.equals(a[i].getLicensePlate()) && a[i].isState()) {
                for (int j = i; j < count - 1; j++) {
                    a[j] = a[j + 1];
                }
                a[count - 1] = null;
                count--;
                return true;
            }
        }
        return false;
    }

    //添加租车信息
    public void tenantInf(Tenant te) {
        if (count >= t.length) {
            Tenant[] tx = new Tenant[t.length + 1000];
            for (int i = 0; i < count; i++) {
                tx[i] = t[i];
            }
            t = tx;
        }
        t[count1++] = te;
    }

    //显示租车信息
    public void tenantShow() {
        System.out.println("序号" + "  姓名" + "  性别" + "  电话" + "  租用车牌" +
                "  租用天数" + "  租用费用");
        for (int i = 0; i < count1; i++) {
            System.out.print(i + 1);
            t[i].tenantShow();

        }
    }

    //总租金
    public double charterMoney() {
        for (int i = 0; i < count1; i++) {
            charterMoney += t[i].getMoney();
        }
        return charterMoney;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public int getCount() {
        return count;
    }

    public int getTally() {
        return tally;
    }
}
